package com.atguigu.springbootdemo.controller;

import com.atguigu.springbootdemo.bean.Customer;
import com.atguigu.springbootdemo.service.CustomerService;
import com.atguigu.springbootdemo.service.impl.CustomerServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @RestController将类标识为Controller ， 作为请求的入口类。
 */
@RestController
public class CustomerController {


    /*@RequestMapping("/hello")
    public String helloController(){
        return "hello world";
    }*/


    /**
     * 请求处理方法
     *
     * @RequestParam 用来将请求路径中的键值对参数映射到方法的形参上
     */
    /*@RequestMapping("/hello")
    public String helloController(@RequestParam("name") String name, @RequestParam("age") Integer age){
        return "hello world, name=" + name + " ,age=" + age;
    }*/


    /**
     * 请求处理方法
     *
     * @PathVariable 用来将请求路径中嵌入的参数映射到方法的形参上
     */
    /*@RequestMapping("/hello/{name}/{age}")
    public String helloController(@PathVariable("name") String name, @PathVariable("age") Integer age) {
        return "hello world, name=" + name + ",age=" + age;
    }*/


    /**
     * 请求处理方法
     * @RequestBody  用来将请求体中的请求参数映射到Bean类中对应的属性上
     */
    @PostMapping("/hello")
    public String helloController(@RequestBody Customer customer){
        return "hello world  , name = " + customer.getName() + " , age = "+ customer.getAge() ;
    }

    @Autowired
    private CustomerService customerService;

    @GetMapping("/get")
    public Customer getCustomer(@RequestParam("id") Integer id){
        return customerService.getCustomerById(id);
    }

}
